<template>
  <div class="initiateConsult">
    <el-dialog
      title="发起会商会审"
      class="dialog"
      :visible="initiateVisible"
      width="30%"
      @close="handleClose"
    >
      <el-form ref="form" :model="form" label-width="80px" :rules="rules">
        <el-form-item label="开始时间" required="true" label-width="100px">
          <el-col :span="8">
            <el-form-item prop="date">
              <el-date-picker
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择日期"
                v-model="form.date"
                style="width: 100%;"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col class="line" :span="2">-</el-col>
          <el-col :span="8">
            <el-form-item prop="time">
              <el-time-picker
                value-format="HH:mm:ss"
                placeholder="选择时间"
                v-model="form.time"
                style="width: 100%;"
              ></el-time-picker>
            </el-form-item>
          </el-col>
        </el-form-item>
        <el-form-item label="发起原因" prop="reason" label-width="100px">
          <el-col :span="18">
            <el-input
              type="textarea"
              :rows="5"
              placeholder="请输入"
              v-model="form.reason"
            ></el-input>
          </el-col>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button class="cancel" @click="handleClose">取 消</el-button>
        <el-button class="sure" @click="addConsult">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { addConsultApi } from "@/api/manageApi.js";
export default {
  props: {
    initiateVisible: {
      type: Boolean,
      default: false
    },
    projectId: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      form: {
        date: "",
        time: "",
        reason: ""
      },
      rules: {
        time: [{ required: true, message: "请选择时间范围", trigger: "blur" }],
        reason: [
          { required: true, message: "请输入发起原因", trigger: "blur" }
        ],
        date: [{ required: true, message: "请选择时间范围", trigger: "blur" }]
      }
    };
  },
  methods: {
    handleClose() {
      this.$refs.form.resetFields();
      this.$emit("update:initiateVisible", false);
    },
    addConsult() {
      this.$refs.form.validate(valid => {
        if (valid) {
          addConsultApi({
            startTime: this.form.date + " " + this.form.time,
            reason: this.form.reason,
            projectId: this.projectId,
            sponsor: JSON.parse(localStorage.getItem("P-User-Info")).id
          }).then(res => {
            if (res.code == 0) {
              this.$emit("update:initiateVisible", false);
              this.$message({
                message: res.msg,
                type: "success"
              });
              this.$emit("refresh");
            }
          });
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.initiateConsult {
  ::v-deep .el-dialog {
    width: 740px !important;
  }
  .line {
    text-align: center;
  }
  .cancel {
    border: 1px solid #4880ff;
    font-size: 14px;
    color: #4880ff;
  }
  .sure {
    background: #4880ff;
    font-size: 14px;
    color: #ffffff;
  }
}
</style>
